package com.coderknock.bbs

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.boot.web.support.SpringBootServletInitializer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession


@SpringBootApplication
@EnableRedisHttpSession
@EnableWebSecurity //才会开启全局权限验证
@ComponentScan("com.coderknock.bbs")
class CoderknockBbsApplication : SpringBootServletInitializer() {
    override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {
        return application.sources(CoderknockBbsApplication::class.java!!)
    }

    /**
     * 提供加密使用的 Bean 由于会被 UserService用到，而 UserService 又是 WebSecurityConfig 配置以来的组件的依赖所以该 Bean 不能放在　WebSecurityConfig　中
     */
    @Bean
    fun passwordEncoder(): BCryptPasswordEncoder = BCryptPasswordEncoder()
}

fun main(args: Array<String>) {
    SpringApplication.run(CoderknockBbsApplication::class.java, *args)
}
